package com.guigu.buy.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.buy.pojo.Stock;
import com.guigu.buy.service.IStockService;
import com.guigu.buy.vo.StockVo;
import com.guigu.buy.vo.Stock_UnAudit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/buy/stock")
public class StockController {
    @Autowired
    private IStockService stockService;
//    查询所有的仓库数据
    @RequestMapping("/list/{pageSize}/{pageNo}")
    @ResponseBody
    public PageInfo<Stock> list(@PathVariable int pageSize,
                                @PathVariable int pageNo,
                                @RequestBody StockVo vo){
        System.out.println(vo);
     return stockService.queryAll(pageNo,pageSize,vo);
 }
    //根据id查询仓库
    @RequestMapping("/getOne/{id}")
    @ResponseBody
    public Stock getOne(@PathVariable int id){
        return stockService.getById(id);
    }
    //无条件查询所有的仓库数据
    @RequestMapping("/queryAll")
    @ResponseBody
    public List<Stock> queryAll(){
        return stockService.list();
    }
    //根据编号修改仓库
    @RequestMapping("/updStock")
    @ResponseBody
    public boolean updStock(@RequestBody Stock stock){
        return stockService.updateById(stock);
    }
    //新增一条仓库
    @RequestMapping("/addStock")
    @ResponseBody
    public boolean addStock(@RequestBody Stock stock){
        stock.setCheckTag("S001-0");
        stock.setOnOff(1);
        stock.setStockAmount(0);
        return stockService.save(stock);
    }
    //查询未审核的仓库
    @RequestMapping("/unAudit/{pageSize}/{pageNo}")
    @ResponseBody
    public PageInfo<Stock> unAudit(@PathVariable int pageSize,
                                   @PathVariable int pageNo,
                                   @RequestBody Stock_UnAudit vo){
                return stockService.unAudit(pageNo,pageSize,vo);
    }
}
